package com.egao.api.controller.orderB;


import com.egao.common.core.annotation.OperLog;
import com.egao.common.core.damon.utils.PhoneUtils;
import com.egao.common.core.web.BaseController;
import com.egao.common.core.web.JsonResult;
import com.egao.orderB.biz.CustomerBiz;
import com.egao.orderB.entity.Customer;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpServletRequest;

//import com.egao.orderB.entity.Bill;
//import com.egao.orderB.service.BillService;

/**
 * api登录相关接口
 * Created by wangfan on 2019-05-29 下午 3:43.
 * http://localhost/swagger-ui.html
 */
@RequestMapping("/api/phone/message")
@RestController
@Api(value = "短信",tags = {"短信"})
public class ApiPhoneMessageController extends BaseController {


    @Autowired
    private CustomerBiz customerBiz;

    /**
     * 添加运费维护列表
     */
    @PreAuthorize("hasAuthority('orderB:bill:list')")
    @PostMapping("/send")
    @ApiOperation(value = "指派司机短信发送",notes = "" +
            "customerId:客户id\n" +
            "billOfLading:提单号\n" +
            "contactsPhone:客户联系方式\n" +
            "driverPhone:司机电话\n" +
            "carNo:车牌\n" +
            "driver:姓名\n" +
            "",httpMethod = "POST")
    public JsonResult send(String customerId, String driverPhone, String billOfLading, String contactsPhone,
                           String carNo, String driver, HttpServletRequest request)  throws Exception{
        //602245【宁波甩手掌柜网络科技有限公司】您好,提单号:{1}已指派给您,请您登陆甩手掌柜小程序,尽快接单,感谢您一直以来对甩手掌柜的支持,如有一问请联系客服(0574)28820591
        PhoneUtils.sendMsg(driverPhone, "602245", new String[]{billOfLading},1);
        int message = 0;
        try {
            Customer customer2 = customerBiz.getById(new Customer(customerId, true));
            message = Integer.valueOf(customer2.getMessage());
        } catch (Exception e) {
        }
        //【宁波甩手掌柜网络科技有限公司】您好,提单号:{1}已被甩手掌柜成功接单,司机师傅信息:{2},感谢您一直以来对甩手掌柜的支持,如有一问请联系客服(0574)28820591
        PhoneUtils.sendMsg(contactsPhone, "597088", new String[]{billOfLading,carNo+"、"
                        +driver+"、"+driverPhone},message);
        return JsonResult.ok("正在发送!");
    }

}
